/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Padda1
 */
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

public class FileEditor 
{
    /**
     * Default empty constructor.
     */
    public FileEditor()
    {

    }
    
    /**
     * Reads the whole file.
     * @param location String. The path of the file.
     * @return The file read is returned.
     * @throws FileNotFoundException 
     */
	public String read(String location) throws FileNotFoundException
	{
            String file = "";
            try
            {
                FileReader fr = new FileReader(location);
                BufferedReader br = new BufferedReader(fr);
                String line = "";
                while((line = br.readLine()) != null)
                {
                    file += line + "\n";
                }
                return file;
            }
            catch(Exception e)
            {
                return "Error with file reading: " + e;
            }
	}
        
	/**
         * Writes a new file with the name given.
         * @param file String. The name of the file to write.
         * @throws IOException 
        */
	public void write(String filename,String content) throws IOException
	{
            BufferedWriter br = new BufferedWriter(new FileWriter(filename));
            br.write(content);
            br.close();	
	}
        
        /**
         * Writes a new file with the name given.
         * @param file String. The name of the file to write.
         * @throws IOException 
        */
//	public void writeOtherType(String filename,String content) throws IOException
//	{
//            BufferedWriter br = new BufferedWriter(new FileWriter(filename));
//            br.write(content);
//            br.close();
//		
//	}
}
